#ifndef _BURST_MODULE_H
#define _BURST_MODULE_H

#define BUS_MODULE_EVENT 1
#define BUS_MODULE_FUNCTION 2
#define BUS_MODULE_IO 4

typedef struct bus_module bus_module_t;
typedef struct bus_kernel bus_kernel_t;


typedef void bus_event_add_t(void *, struct bus_event *);
typedef void bus_event_del_t(void *, struct bus_event *);
typedef struct list_head *bus_event_process_t(void *);

typedef int bus_event_get_event_t(bus_event_t *);

typedef uint8_t *bus_event_get_buf_t(bus_event_t *);
typedef int bus_event_get_size_t(bus_event_t *);
typedef void *bus_event_get_data_t(bus_event_t *);
typedef void bus_event_set_data_t(bus_event_t *, void *);

typedef void bus_callback_t(bus_event_t *);
typedef bus_handle_event_t *bus_get_callback_t(bus_event_t *);
typedef void bus_set_callback_t(bus_event_t *, 
							  bus_handle_event_t *);

typedef bus_event_t *bus_get_socket_t(int, 
							int);
typedef int bus_add_binding_t(bus_event_t *, 
					struct sockaddr_in *);
typedef void bus_add_sending_t(bus_event_t *, 
				char *, 
				int, 
				int);
typedef void bus_add_recving_t(bus_event_t *, 
				char *, 
				int, 
				int);
typedef void bus_add_connecting_t(bus_event_t *, 
				struct sockaddr *,
				int);
typedef void bus_add_accepting_t(bus_event_t *, 
				struct sockaddr *,
				int);
typedef void bus_engine_loop_t(void *);


typedef void bus_command_func_t(int, char **);


typedef struct bus_kernel {
	bus_event_get_event_t *bus_event_get_event;
	bus_event_get_buf_t *bus_event_get_buf;
	bus_event_get_size_t *bus_event_get_size;
	bus_event_get_data_t *bus_get_data;
	bus_event_set_data_t *bus_set_data;
	bus_callback_t *bus_callback;
	bus_get_callback_t *bus_get_callback;
	bus_set_callback_t *bus_set_callback;
	bus_get_socket_t *bus_get_socket;
	bus_add_binding_t *bus_add_binding;
	bus_add_sending_t *bus_add_sending;
	bus_add_recving_t *bus_add_recving;
	bus_add_connecting_t *bus_add_connecting;
	bus_add_accepting_t *bus_add_accepting;
	bus_engine_loop_t *bus_engine_loop;
	struct rb_node node;
} bus_kernel_t;


typedef struct bus_module_info {
	int type;
	char *name;
	char *author;
	char *descript;
	char *version;
} bus_module_desc_t;

typedef struct bus_event_module {
	bus_event_add_t *add;
	bus_event_del_t *del;
	bus_event_process_t *process;
} bus_event_module_t;

typedef struct bus_command {
	char *command;
	bus_command_func_t *func;
	struct rb_node node;
} bus_command_t;


typedef bus_module_t *bus_module_init_t(bus_kernel_t *);

typedef struct bus_module {
	bus_module_desc_t *info;
	bus_module_init_t *init;
	struct {
		int nr_command;
		bus_command_t *command;
	};
	union {
		void *addition;
	};
	struct rb_node node;
} bus_module_t;


int bus_module_insert(bus_module_t *);
bus_module_t *bus_module_search(char *);
void bus_module_erase(char *);


#endif
